using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyMES.Dto;
using MyMES.IServices.Allots;
using System.Threading.Tasks;
using VOL.Core.Controllers.Basic;
using VOL.Core.Filters;
using VOL.Core.Utilities.Response;
using VOL.Entity.AttributeManager;
using VOL.Entity.DomainModels;
using VOL.Entity.DomainModels.Core;
using VOL.Entity.DomainModels.Repository;

namespace VOL.WebApi.Controllers.MyMES
{
    /// <summary>
    /// 调拨管理控制器
    /// </summary>
    [Route("api/Allot")]
    [ApiController]
    [AllowAnonymous]
    [PermissionTable(Name = "Allot")]
    public class AllotController : ApiBaseController<IAllotService>
    {
        private readonly IAllotService _allotService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="allotService">调拨服务</param>
        public AllotController(IAllotService allotService)
            : base(allotService)
        {
            _allotService = allotService;
        }

        /// <summary>
        /// 获取调拨列表
        /// </summary>
        /// <param name="dto">查询条件</param>
        /// <returns>调拨列表</returns>
        [HttpPost("GetAllot")]
        public async Task<PageGridData<Allot>> GetAllot([FromBody] GetAllotDto dto)
        {
            return await _allotService.GetAllotAsync(dto);
        }

        /// <summary>
        /// 创建调拨
        /// </summary>
        /// <param name="entity">调拨实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("CreateAllot")]
        public async Task<WebResponseContent> CreateAllot([FromBody] Allot entity)
        {
            return await _allotService.CreateAllotAsync(entity);
        }

        /// <summary>
        /// 更新调拨
        /// </summary>
        /// <param name="entity">调拨实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("UpdateAllot")]
        public async Task<WebResponseContent> UpdateAllot([FromBody] Allot entity)
        {
            return await _allotService.UpdateAllotAsync(entity);
        }

        /// <summary>
        /// 删除调拨
        /// </summary>
        /// <param name="ids">调拨ID列表，以逗号分隔的字符串</param>
        /// <returns>操作结果</returns>
        [HttpPost("DelAllot")]
        public async Task<WebResponseContent> DelAllot([FromQuery] string ids)
        {
            return await _allotService.DelAllotA(ids);
        }
        
        /// <summary>
        /// 根据调拨ID获取物料列表
        /// </summary>
        /// <param name="allotId">调拨ID</param>
        /// <returns>物料列表</returns>
        [HttpGet("GetAllotMaterialListByAllotId")]
        public async Task<WebResponseContent> GetAllotMaterialListByAllotId([FromQuery] int allotId)
        {
            return await _allotService.GetAllotMaterialListByAllotId(allotId);
        }
        
        /// <summary>
        /// 创建调拨物料
        /// </summary>
        /// <param name="entity">调拨物料实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("CreateAllotMaterial")]
        public async Task<WebResponseContent> CreateAllotMaterial([FromBody] AllotMaterial entity)
        {
            return await _allotService.CreateAllotMaterialAsync(entity);
        }
        
        /// <summary>
        /// 更新调拨物料
        /// </summary>
        /// <param name="entity">调拨物料实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("UpdateMaterial")]
        public async Task<WebResponseContent> UpdateMaterial([FromBody] AllotMaterial entity)
        {
            return await _allotService.UpdateMaterialAsync(entity);
        }
        
        /// <summary>
        /// 删除调拨物料
        /// </summary>
        /// <param name="ids">调拨物料ID列表，以逗号分隔的字符串</param>
        /// <returns>操作结果</returns>
        [HttpPost("DelAllotMaterial")]
        public async Task<WebResponseContent> DelAllotMaterial([FromQuery] string ids)
        {
            return await _allotService.DelAllotMaterialAsync(ids);
        }
        
        /// <summary>
        /// 获取物料列表
        /// </summary>
        /// <param name="dto">查询条件</param>
        /// <returns>物料列表</returns>
        [HttpPost("GetMaterial")]
        public async Task<PageGridData<MaterialProduct>> GetMaterial([FromBody] GetMaterialDto dto)
        {
            return await _allotService.GetMaterialAsync(dto);
        }
        
        /// <summary>
        /// 获取物料类型列表
        /// </summary>
        /// <returns>物料类型列表</returns>
        [HttpGet("GetMaterialTypeList")]
        public async Task<WebResponseContent> GetMaterialTypeList()
        {
            return await _allotService.GetMaterialTypeList();
        }
    }
} 